using System;
using Tridion.Gateway;
using System.Text;
using System.Xml;
using System.Data;
using System.Reflection;
using System.ServiceModel;
using System.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using TDS = Tridion.ContentManager.Interop.TDS;
using COM = System.Runtime.InteropServices.ComTypes;
using TDSDefines = Tridion.ContentManager.Interop.TDSDefines;

namespace Tridion.Gateway
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
    public class TridionService : ITridionContext
    {
        Context tdse;

        public TridionService()
            : this(ConfigurationManager.AppSettings["Tridion.Gateway.TridionService.ImpersonateUser"] as String)
        {
        }


        public TridionService(String Identity)
        {
            tdse = new Context(Identity);
        }

        
        public string GetVersion()
        {
            return tdse.GetVersion();
        }

        
        public Component GetComponent(string ComponentId, string PublicationId, bool EditMode, int Version)
        {
            return tdse.GetComponent(ComponentId, PublicationId, EditMode, Version);  
        }

        
        public ComponentTemplate GetComponentTemplate(string ComponentTemplateId, string PublicationId, bool EditMode, int Version)
        {
            return tdse.GetComponentTemplate(ComponentTemplateId, PublicationId, EditMode, Version); 
        }

        
        public Schema[] GetDestinationProtocols()
        {
            return tdse.GetDestinationProtocols();
        }

        
        public string GetEnumerationValues(string enumerations)
        {
            return tdse.GetEnumerationValues(enumerations);
        }

        
        public Folder GetFolder(string FolderId, string PublicationId)
        {
            return tdse.GetFolder(FolderId, PublicationId);
        }

        
        public virtual StructureGroup GetStructureGroup(string StructureGroupId, string PublicationId)
        {
            return tdse.GetStructureGroup(StructureGroupId, PublicationId);
        }

        
        public Group[] GetGroups()
        {
            return tdse.GetGroups();
        }

        
        public string GetListApprovalStatuses(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListApprovalStatuses(ColumnFilter);
        }

        
        public string GetListDestinationProtocols(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListDestinationProtocols(ColumnFilter);     
        }

        
        public string GetListDirectoryServices(ListRowFilter[] RowFilters)
        {
            return tdse.GetListDirectoryServices(RowFilters);
        }

        
        public string GetListDirectoryServiceTestUsers(string DirectoryService, string SearchDN, TDSDefines.EnumDirectorySearchTypes SearchType)
        {
            return tdse.GetListDirectoryServiceTestUsers(DirectoryService, SearchDN, SearchType);
        }

            
        #region custom
        
        public Item[] GetPublicationItems(Publication Publication)
        {
            return tdse.GetPublicationItems(Publication);
        }

        public Item[] GetStructureGroupItems(StructureGroup StructureGroup)
        {
            return tdse.GetStructureGroupItems(StructureGroup);
        }

        public Item[] GetFolderItems(Folder Folder)
        {
            return tdse.GetFolderItems(Folder);
        }

        #endregion

        
        public string GetListItems(TDSDefines.ListColumnFilter ColumnFilter, ListRowFilter[] RowFilters)
        {
            return tdse.GetListItems(ColumnFilter, RowFilters);
        }

        
        public string GetPublicationListItems(String PublicationId, TDSDefines.ListColumnFilter ColumnFilter, ListRowFilter[] RowFilters)
        {
            return tdse.GetPublicationListItems(PublicationId, ColumnFilter, RowFilters);
        }

        
        public string GetStructureGroupListItems(String PublicationId, String StructureGroupId, TDSDefines.ListColumnFilter ColumnFilter, ListRowFilter[] RowFilters)
        {
            return GetStructureGroupListItems(PublicationId, StructureGroupId, ColumnFilter, RowFilters); 
        }

        
        public string GetFolderListItems(String PublicationId, String FolderId, TDSDefines.ListColumnFilter ColumnFilter, ListRowFilter[] RowFilters)
        {
            return tdse.GetFolderListItems(PublicationId, FolderId, ColumnFilter, RowFilters); 
        }
        
        
        public string GetListMultimediaTypes(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListMultimediaTypes(ColumnFilter);
        }

        
        public string GetListNonSystemUsers(TDSDefines.EnumNonSystemUserType UserType, string NameOfDomainOrDirectory)
        {
            return tdse.GetListNonSystemUsers(UserType, NameOfDomainOrDirectory);
        }

        
        public string GetListPublications(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListPublications(ColumnFilter);
        }

        
        public string GetListPublicationTargets(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListPublicationTargets(ColumnFilter);
        }

        
        public string GetListTargetTypes(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListTargetTypes(ColumnFilter);
        }

        
        public string GetListTemplateTypes(TDSDefines.ListColumnFilter ColumnFilter, ListRowFilter[] RowFilters)
        {
            return tdse.GetListTemplateTypes(ColumnFilter, RowFilters);
        }

        
        public string GetListTrustees(TDSDefines.TrusteeType TrusteeTypes, TDSDefines.ListColumnFilter ColumnFilter, ListRowFilter[] RowFilters)
        {
            return tdse.GetListTrustees(TrusteeTypes, ColumnFilter, RowFilters);
        }

        
        public string GetListVirtualFolderTypes(TDSDefines.ListColumnFilter ColumnFilter)
        {
            return tdse.GetListVirtualFolderTypes(ColumnFilter);
        }

        
        public string GetLocalizedErrorXML(string ErrorXML, int LangID)
        {
            return tdse.GetLocalizedErrorXML(ErrorXML, LangID);
        }

        
        public MultimediaType[] GetMultimediaTypes()
        {
            return tdse.GetMultimediaTypes();
        }

        
        public Page GetPage(string PageId, string PublicationId, bool EditMode, int Version)
        {
            return tdse.GetPage(PageId, PublicationId, EditMode, Version);
        }

        
        public PageTemplate GetPageTemplate(string PageTemplateId, string PublicationId, bool EditMode, int Version)
        {
            return GetPageTemplate(PageTemplateId, PublicationId, EditMode, Version);
        }

        
        public Publication GetPublication(string PublicationId)
        {
            return tdse.GetPublication(PublicationId);
        }

        
        public virtual Publication[] GetPublications()
        {
            return tdse.GetPublications();
        }

        
        public virtual PublicationTarget GetPublicationTarget(string PublicationTargetId)
        { 
            return tdse.GetPublicationTarget(PublicationTargetId);
        }

        
        public virtual PublicationTarget[] GetPublicationTargets()
        {
            return tdse.GetPublicationTargets();
        }

        
        public virtual User[] GetUsers()
        {
            return tdse.GetUsers();
        }

        
        public virtual Schema[] GetVirtualFolderTypes()
        {
            return tdse.GetVirtualFolderTypes();
        }

        
        public void FlushCache(string ObjectOrUri)
        {
            tdse.FlushCache(ObjectOrUri);
        }

    
        public ListRowFilter CreateListRowFilter()
        {
            return tdse.CreateListRowFilter();
        }

  
        public virtual string GetSystemXSD(string NameOrNamespaceUri)
        {
            return tdse.GetSystemXSD(NameOrNamespaceUri);
        }

        
        public virtual TargetType GetTargetType(string TargetTypeId)
        {
            return tdse.GetTargetType(TargetTypeId);
        }

        
        public virtual TargetType[] GetTargetTypes()
        {
            return GetTargetTypes();
        }

        
        public virtual PublishTransaction GetPublishTransaction(string PublishTransactionId)
        {
            return tdse.GetPublishTransaction(PublishTransactionId);
        }

       
        public String GetObject(string Uri, string PublicationId, TDSDefines.XMLReadFilter Filter, bool ShallowCopy)
        {
            return tdse.GetObject(Uri, PublicationId, Filter, ShallowCopy);
        }


        public String GetXML(string Uri, TDSDefines.XMLReadFilter Filter)
        {
            return tdse.GetXML(Uri, Filter);
        }


        public String[] GetXMLForEach(string[] URIs, TDSDefines.XMLReadFilter filter)
        {
            return tdse.GetXMLForEach(URIs, filter);
        }


        public string GetNewObject(TDSDefines.ItemType ItemType, String PublicationId, String Folder, String Title, String Schema, String Xml)
        {
            return tdse.GetNewObject(ItemType, PublicationId, Folder, Title, Schema, Xml); 
        }

        
        public string ExecuteProc(string ProcedureName, Dictionary<string, string> Paramaters)
        {
            return tdse.ExecuteProc(ProcedureName, Paramaters);
        }
       
    }
}
